import CompositeItem from './compositeItem';
import Model from './common/model-base'
export default class Composite extends Model {

    $config = {
        id: 'id',
        $create: this.$urls.create_composite,
        $update: this.$urls.create_composite,
    }

    // constructor() {
    //     this.compositeItems = [];
    //     // 测试
    //     // this.compositeItems = [{ compositeItemName: 't1', compositeItemAmount: 2 },
    //     // { compositeItemName: 't2', compositeItemAmount: 3 }]
    // }

    /**
     * 合成物名称
     */
    compositeName = ''

    /**
     * 需要的元素
     */
    compositeItems = []

    /**
     * 默认是不被选中的
     */
    checked = false

    /**
     * 清单项压栈
     * @param {*} element 
     */
    pushElement(element) {
        this.compositeItems.push(Object.assign(new CompositeItem(), element));
    }

    /**
     * 生成默认清单标题
     */
    newDefaultCompositeName() {
        var date = new Date();
        let fullYear = date.getFullYear();
        let fullMonth = date.getMonth() + 1;
        let fullDay = date.getDate();

        this.compositeName = fullYear + '-' + fullMonth + '-' + fullDay + ' 购物清单';
    }
}